﻿using System;
using System.Web;

using OctoOS.UI;
using OctoOS;


public partial class __deletePage : OOSPage
{
	class PathInfo
	{
		[PathInfoMember(0)]
		[RangeValidator(1, Int64.MaxValue)]
		[IntegerBase(64)]
		internal long ArticleID = 0;

		[PathInfoMember(1)]
		internal long PageID = 0;
	}

	PathInfo _pathInfo;

	protected void Page_Init(object sender, EventArgs e)
	{
		_pathInfo = EnablePathInfo<PathInfo>();
	}

    protected void Page_Load(object sender, EventArgs e)
    {
		PageTitle = Resources.Main.deletePage_Title;
		var article = ApiService.GetArticle(OOSRequest.Current, _pathInfo.ArticleID);

		if(!OOSRequest.Current.IsModerator &&
				article.UserID != OOSRequest.Current.UserID)
		{
			throw new HttpException();
		}

		var page = article.GetPage(_pathInfo.PageID, true);
		if(page == null)
			throw new ApplicationException();

		deleteBox.SetContent(String.Format(Resources.Main.shared_DeletePage, page.Title));
		deleteBox.AddSubmit(Resources.Main.shared_Yes, DeletePage);
		deleteBox.AddCancel(Resources.Main.shared_No, Urls.GetEditArticle(_pathInfo.ArticleID));
    }

	protected void DeletePage(object sender, EventArgs e)
	{
		ApiService.DeletePage(OOSRequest.Current, _pathInfo.ArticleID, _pathInfo.PageID);
		Response.Redirect(Urls.GetEditArticle(_pathInfo.ArticleID));
	}
}